<?php

class Application_Model_DbTable_StoreLocation extends Application_Model_DbTable_DomainObject{
    
    protected $_name = 'uuch_storelocation';
    
    public function getMapper() {
        return array('id','userId','locationNo','status','library','datecreated');
    }
    
    public function releaseLocation(){
        $sql = "select l.locationNo from uuch_storelocation l where l.status =1 and l.locationNo not in 
            (select s.locationNo from uuch_storeitem s where s.interior =1 and s.isdelete != 1 and s.locationNo != '' group by s.locationNo)";
        $db = $this->getAdapter();
        $result = $db->query($sql)->fetchAll();
        if(is_array($result)){
            foreach($result as $val){
                $sql2 = "update uuch_storelocation set userId = null, status = 0 where locationNo = '".$val['locationNo']."'";
                $db->query($sql2);
            }
        }
    }
}
